package com.zhen.aikan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhen.aikan.service.IVodDetailService;
import com.zhen.aikan.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author LiJiaZhen
 * @date 2023/9/14 22:52
 */
@Api(tags = "搜索控制器")
@RestController
@RequestMapping("/api/search")
public class SearchController {
    @Autowired
    private IVodDetailService vodDetailService;

    @ApiOperation("模糊搜索匹配项")
    @GetMapping("/matchingItems")
    public Result matchingItems(@RequestParam(name = "searchText",defaultValue = "") String searchText){
        List<Map<String,Object>> matchingItems = vodDetailService.getVodNameMatchingItems(searchText);
        return Result.ok(matchingItems);
    }

    @ApiOperation("模糊搜索视频")
    @GetMapping("/searchVod")
    public Result getVodForSearchText(@RequestParam(name = "searchText")String searchText,
                                      @RequestParam(name = "typeName") String typeName,
                                      @RequestParam(name = "current") Integer current,
                                      @RequestParam(name = "size") Integer size){
        Page<Map<String, Object>> page = vodDetailService.fuzzySearchVodForSearchText(searchText,typeName,current,size);
        return Result.ok(page);
    }
}
